/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.home.dao;

import com.home.common.utils.HibernateUtil;
import com.home.mapping.Account;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author pnduy
 */
public class AccountDao extends BaseDao{
    
    /**
     * find employee for login by username and password
     * @param username
     * @param password
     * @return 
     */
    public Account findAccountForLogin(String username, String password) {
        Account acc = new Account();
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            Criteria criteria = session.createCriteria(Account.class);
            criteria.add(Restrictions.eq("username",username));
            criteria.add(Restrictions.eq("password",password));
            
            List result = criteria.list();
            if (result.size() > 0) {
                acc = (Account)result.get(0);
            }
           
            Hibernate.initialize(acc.getAgent().getTeam().getVenture());
        } catch (Exception e) {
        } finally {
            session.close();
        }
        return acc;
    } 
}
